 @include "readarff.awk"

 BEGIN{ BeforeEachRow="nbTest" ; TheK = 1 ; TheM = 2}

 function nbTest(c,row,     l,what) {
   if(row > 1) {
		what = nbClassify(c,row,l,TheK,TheM)
		print  Data[row,K], what, l[what]
 }}
 function nbClassify(c,row,l,k,m,\
                             n,nklasses,like,klass,nklass,\
                             key,prior,temp,inc,col,val,mu,s,what) {        
   n        = Fall[c,K,"_"] # number of instances
   nklasses = length(Klass[c]) # number of hypotheses
   like     = -10000000000;         # smaller than any log
   for(klass in Klass[c]) {
	   what = what ? what : klass # if all else fails, what is any klass
       nklass = Fall[c,K,klass]
       prior  = (nklass + k)/(n + (k*nklasses));
       temp   = log(prior)
       for(col in Name) {
          if (col != K)  {
              if ( (val = Data[row,col] ) != Missing ) {
                 key = c _ col _ klass
				 if (col in Sym) {
			          temp += log((F[key][val]+m*prior)/(nklass+m))
                 } else if (N[key] > 1) {
                      mu  = Sum[key] / N[key]
                      s   = stddev(N[key],Sum[key],SumSq[key])
                      temp +=  log(gaussianPdf(mu,s,val))
       }}}}
       l[klass]= temp
       if ( temp >= like ) {like = temp; what=klass}
   }
   return what
 }

